package com.briup.pts.web.controller;

import com.briup.pts.config.response.Result;
import com.briup.pts.service.UploadService;
import com.briup.pts.util.UploadUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author iknow
 * @description
 * @data 2024/11/26-14:25
 */
@Tag(name = "文件上传模块")
@RequiredArgsConstructor
@RestController
public class UploadController {
    private final UploadService uploadService;
    /**
     * 文件上传接口
     *
     * @param file 上传的文件，参数名为 "img"
     * @return 上传后的文件 URL
     */
    @Operation(summary = "文件上传", description = "接收文件并上传到对象存储服务")
    @PostMapping("/file/upload")
    public Result<String> upload(@RequestPart("img") MultipartFile file){
        String url = String.format(UploadUtil.uploadToOss(file), file.getOriginalFilename());

        return Result.success(url).apply("操作成功");
    }
}

